package com.tuinui.trade.utility;
/*
* created by kaweepapkongkittisan
*
*/




import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;

public abstract class BasedPriceExtractUtility {

	public String leftTrim(String s){
        return s.replaceAll("^\\s+", "");
	}
	
	
	public String rightTrim(String s){
        return s.replaceAll("\\s+$", "");
	}
	
	public String leftRightTrim(String s){
		return leftTrim(rightTrim(s));
	}
	

	
	public BigDecimal convertToNum(String s)throws Exception{
		s = leftRightTrim(s);
		if (s.equals("-")){
			return null;
		}
		s=s.replace("+", "");
		Locale locale = Locale.US;
		Number number = NumberFormat.getNumberInstance(locale).parse(s);
		
		BigDecimal b = new BigDecimal(number.floatValue());
		b.setScale(2, BigDecimal.ROUND_FLOOR);
		//b.unscaledValue()
		return b;
	}


	
}
